package org.hzz.application.handler;

import io.gitee.pkmer.convention.converter.TargetAndSourceConverter;
import io.gitee.pkmer.designpattern.strategy.AbstractExecuteStrategy;
import lombok.Setter;
import org.hzz.application.command.IssueCouponCmd;
import org.hzz.promotions.domain.entity.CouponEntity;
import org.hzz.promotions.domain.service.CouponDomainService;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author <a href="mailto:1193094618@qq.com">pkmer</a>
 * <br>
 * <a href = "https://gitee.com/developeros/videos-online">Code Repository</a>
 * At 2024/8/30
 */
@Component
public class IssueCouponCmdHandler implements AbstractExecuteStrategy<IssueCouponCmd,Void> {

    @Setter(onMethod_ = @Autowired)
    private CouponDomainService couponDomainService;
    @Override
    public String mark() {
        return IssueCouponCmd.MARK;
    }

    @Override
    public void execute(IssueCouponCmd cmd) {
        CouponEntity coupon = Converter.INSTANCE.toTarget(cmd);
        couponDomainService.beginIssue(coupon);
    }

    @Mapper

    interface Converter extends TargetAndSourceConverter<CouponEntity,IssueCouponCmd>{
        Converter INSTANCE = Mappers.getMapper(Converter.class);
    }
}
